package com.zuxia.controller;

import com.zuxia.service.PayService;
import com.zuxia.utils.R;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @className: PayController
 * @Description: TODO
 * @version: v1.８.0
 * @author: Liuxin-G
 * @date: 2024/11/13 9:40
 */
@RestController
@RequestMapping("/order/pay")
public class PayController {
    @Resource
    private PayService payService;

    @ApiOperation("在线支付")
    @GetMapping("/payment/{id}/{price}")
    public R payment(@PathVariable("id") String orderId,@PathVariable("price") Float price) throws Exception{
        System.out.println(price);
        return R.ok().message("表单").data("payment", payService.payment(orderId,price));
    }
    //退款
    @PostMapping("/refund/{id}/{price}")
    @ApiOperation("订单退款")
    public R refund(@PathVariable("id") String orderId,@PathVariable("price") Float price) throws Exception{
        //退款
        try {
            boolean refund = payService.refund(orderId,price);
            if(refund){
                return R.ok().message("退款成功");
            }else {
                return R.error().message("退款失败");
            }
        } catch (Exception e) {
            return R.error().message("退款失败");
        }
    }
}
